//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if !defined(_GDIMISC_H_)
#define _GDIMISC_H_

typedef UInt32 gal_pixel;


// handle type and child type.
#define TYPE_HWND           0x01
    #define TYPE_MAINWIN    0x11
    #define TYPE_CONTROL    0x12
#define TYPE_HMENU          0x02
    #define TYPE_MENUBAR    0x21
    #define TYPE_PPPMENU    0x22
    #define TYPE_NMLMENU    0x23
#define TYPE_HACCEL         0x03
#define TYPE_HCURSOR        0x05
#define TYPE_HICON          0x07
#define TYPE_HDC            0x08
    #define TYPE_SCRDC      0x81
    #define TYPE_GENDC      0x82
    #define TYPE_MEMDC      0x83

// RGB triple structure.
typedef struct _RGB
{
    // the red component of a RGB triple.
    Byte r;
    // the green component of a RGB triple.
    Byte g;
    // the blue component of a RGB triple.
    Byte b;
    // Reserved for alignment,
    // maybe used for the alpha component of a RGB triple.
    Byte a;
} RGB, *PRGB;

extern gal_pixel SysPixelIndex [17];
#define PIXEL_invalid       0
#define PIXEL_transparent   SysPixelIndex[0]
#define PIXEL_darkblue      SysPixelIndex[1]
#define PIXEL_darkgreen     SysPixelIndex[2]
#define PIXEL_darkcyan      SysPixelIndex[3]
#define PIXEL_darkred       SysPixelIndex[4]
#define PIXEL_darkmagenta   SysPixelIndex[5]
#define PIXEL_darkyellow    SysPixelIndex[6]
#define PIXEL_darkgray      SysPixelIndex[7]
#define PIXEL_lightgray     SysPixelIndex[8]
#define PIXEL_blue          SysPixelIndex[9]
#define PIXEL_green         SysPixelIndex[10]
#define PIXEL_cyan          SysPixelIndex[11]
#define PIXEL_red           SysPixelIndex[12]
#define PIXEL_magenta       SysPixelIndex[13]
#define PIXEL_yellow        SysPixelIndex[14]
#define PIXEL_lightwhite    SysPixelIndex[15]
#define PIXEL_black         SysPixelIndex[16]

// Compatiblity definitions
#define COLOR_invalid       PIXEL_invalid
#define COLOR_transparent   PIXEL_transparent
#define COLOR_darkred       PIXEL_darkred
#define COLOR_darkgreen     PIXEL_darkgreen
#define COLOR_darkyellow    PIXEL_darkyellow
#define COLOR_darkblue      PIXEL_darkblue
#define COLOR_darkmagenta   PIXEL_darkmagenta
#define COLOR_darkcyan      PIXEL_darkcyan
#define COLOR_lightgray     PIXEL_lightgray
#define COLOR_darkgray      PIXEL_darkgray
#define COLOR_red           PIXEL_red
#define COLOR_green         PIXEL_green
#define COLOR_yellow        PIXEL_yellow
#define COLOR_blue          PIXEL_blue
#define COLOR_magenta       PIXEL_magenta
#define COLOR_cyan          PIXEL_cyan
#define COLOR_lightwhite    PIXEL_lightwhite
#define COLOR_black         PIXEL_black

#define SysColorIndex       SysPixelIndex

#define BM_TRANSPARENT          1
#define BM_OPAQUE               0

#define PT_SOLID                0
#define BT_SOLID                0

#define SYSLOGFONT_DEFAULT          0
#define SYSLOGFONT_WCHAR_DEF        1
#define SYSLOGFONT_FIXED            2
#define SYSLOGFONT_CAPTION          3
#define SYSLOGFONT_MENU             4
#define SYSLOGFONT_CONTROL          5

#define NR_SYSLOGFONTS              6

typedef struct DECL_PACKED _tagBITMAPINFOHEADER
{
    UInt32 biSize;
    Int32 biWidth;
    Int32 biHeight;
    UInt16 biPlanes;
    UInt16 biBitCount;
    UInt32 biCompression;
    UInt32 biSizeImage;
    Int32 biXPelsPerMeter;
    Int32 biYPelsPerMeter;
    UInt32 biClrUsed;
    UInt32 biClrImportant;
} BITMAPINFOHEADER;

typedef struct DECL_PACKED _tagRGBQUAD
{
    UInt8 rgbBlue;
    UInt8 rgbGreen;
    UInt8 rgbRed;
    UInt8 rgbReserved;
} RGBQUAD;

typedef struct tagBITMAPINFO {
    BITMAPINFOHEADER    bmiHeader;
    RGBQUAD             bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;

// defgroup err_codes Error codes
#define ERR_OK                   0
#define ERR_INV_HWND            -1
#define ERR_QUEUE_FULL          -2

#define ERR_INVALID_HANDLE      -3
#define ERR_INVALID_HMENU       -4
#define ERR_INVALID_POS         -5
#define ERR_INVALID_ID          -6
#define ERR_RES_ALLOCATION      -7

#define ERR_CTRLCLASS_INVNAME   -8
#define ERR_CTRLCLASS_INVLEN    -9
#define ERR_CTRLCLASS_MEM       -10
#define ERR_CTRLCLASS_INUSE     -11

#define ERR_ALREADY_EXIST       -12
#define ERR_NO_MATCH            -13
#define ERR_BAD_OWNER           -14

#define ERR_IME_TOOMUCHIMEWND   -15
#define ERR_IME_NOSUCHIMEWND    -16
#define ERR_IME_NOIMEWND        -17

#define ERR_CONFIG_FILE         -18
#define ERR_FILE_IO             -19
#define ERR_GFX_ENGINE          -20
#define ERR_INPUT_ENGINE        -21
#define ERR_NO_ENGINE           -22



#define BMP_TYPE_NORMAL         0x00
#define BMP_TYPE_RLE            0x01
#define BMP_TYPE_ALPHA          0x02
#define BMP_TYPE_ALPHACHANNEL   0x04
#define BMP_TYPE_COLORKEY       0x10
#define BMP_TYPE_PRIV_PIXEL     0x20

/** Expanded device-dependent bitmap structure. */
typedef struct tagBITMAP
{
    /**
     * Bitmap types, can be OR'ed by the following values:
     *  - BMP_TYPE_NORMAL\n
     *    A nomal bitmap, without alpha and color key.
     *  - BMP_TYPE_RLE\n
     *    A RLE encoded bitmap, not used so far.
     *  - BMP_TYPE_ALPHA\n
     *    Per-pixel alpha in the bitmap.
     *  - BMP_TYPE_ALPHACHANNEL\n
     *    The \a bmAlpha is a valid alpha channel value.
     *  - BMP_TYPE_COLORKEY\n
     *    The \a bmColorKey is a valid color key value.
     *  - BMP_TYPE_PRIV_PIXEL\n
     *    The bitmap have a private pixel format.
     */
    Int32  bmType;
    /** The width of the bitmap */
    Int32  bmWidth;
    /** The height of the bitmap */
    Int32  bmHeight;
    /** The pitch of the bitmap */
    Int32  bmWidthBytes;
    UInt16  bmPlanes;
    /** The bits per piexel. */
    UInt16  bmBitsPixel;
    /** The bits of the bitmap */
    PVoid bmBits;
}BITMAP, *PBITMAP;


#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif

#define MYBMP_FLOW_DOWN         0x00000010
#define MYBMP_FLOW_UP           0x00000020

#define OBJ_PEN             1
#define OBJ_BRUSH           2
#define OBJ_DC              3
#define OBJ_PAL             5
#define OBJ_FONT            6
#define OBJ_BITMAP          7
#define OBJ_REGION          8
#define OBJ_MEMDC           10
#define OBJ_ENHMETADC       12
#define OBJ_ENHMETAFILE     13

#define MIN_OBJ_TYPE        OBJ_PEN
#define MAX_OBJ_TYPE        OBJ_ENHMETAFILE


#endif // _GDI_H_
